package com.exp.practice.base.user.service.impl;

import com.exp.practice.base.exception.MyException;
import com.exp.practice.base.user.dao.UserDao;
import com.exp.practice.base.user.domain.User;
import com.exp.practice.base.user.service.UserService;
import com.exp.practice.workbench.dao.StudentDao;
import com.exp.practice.workbench.dao.TeacherDao;
import com.exp.practice.workbench.domain.Student;
import com.exp.practice.workbench.domain.Teacher;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
   @Resource
   private UserDao userDao;

   @Resource
   private StudentDao studentDao;

   @Resource
   private TeacherDao teacherDao;


   @Override
   public Student stuLogin(User user) throws MyException {
      //获得用户信息
      User user1=userDao.getUser(user);
      Student student=new Student();
      if(user1==null){
         throw new MyException("账号或密码错误");
      }else {
         Integer uid = user1.getId();
          student=studentDao.getStudentByUid(uid);
      }
      return student;
   }

      @Override
      public Teacher teaLogin(User user) throws MyException {
         //获得用户信息
         User user1=userDao.getUser(user);
         Teacher teacher=new Teacher();
         if(user1==null){
            throw new MyException("账号或密码错误");
         }else {
            Integer uid = user1.getId();
           teacher= teacherDao.getTeacherByUid(uid);
         }
            return teacher;
         }
}
